//
//  LZStaffSelectAccessCell.m
//  laziz_Merchant
//
//  Created by xbnzd on 17/3/2.
//  Copyright © 2017年 XBN. All rights reserved.
//

#import "LZStaffSelectAccessCell.h"
#import "LZStaffModel.h"

@interface LZStaffSelectAccessCell()
@property (weak, nonatomic) IBOutlet UILabel *cellNameLabel;
@property (weak, nonatomic) IBOutlet UIImageView *promotionStateImg;
@property (weak, nonatomic) IBOutlet UIImageView *checkoutStateImg;
@property (weak, nonatomic) IBOutlet UILabel *promotionLabel;
@property (weak, nonatomic) IBOutlet UILabel *checkoutLabel;

@property (assign, nonatomic) BOOL selectCheckout; //选中了结款权限
@property (assign, nonatomic) BOOL selectPromotion; //选中了发优惠的权限
@end

@implementation LZStaffSelectAccessCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.cellNameLabel.text = LZLocalizedString(@"staff_permission", nil);
    self.promotionLabel.text = LZLocalizedString(@"staff_new_promotion", nil);
    self.checkoutLabel.text = LZLocalizedString(@"staff_customer_checkout", nil);
}

#pragma mark -
#pragma mark data
- (void)loadData:(LZStaffModel *)staffModel
{
    if (staffModel.role == 1) {//结账权限
        self.selectCheckout = YES;
        self.selectPromotion = NO;
        self.checkoutStateImg.highlighted = YES;
        self.promotionStateImg.highlighted = NO;
    }else if (staffModel.role == 2){//优惠权限
        self.selectCheckout = NO;
        self.selectPromotion = YES;
        self.promotionStateImg.highlighted = YES;
        self.checkoutStateImg.highlighted = NO;
    }else if (staffModel.role == 3){
        self.selectCheckout = YES;
        self.selectPromotion = YES;
        self.promotionStateImg.highlighted = YES;
        self.checkoutStateImg.highlighted = YES;
    }else{
        self.selectCheckout = NO;
        self.selectPromotion = NO;
        self.promotionStateImg.highlighted = NO;
        self.checkoutStateImg.highlighted = NO;
    }
}

- (void)returnSelectedResult
{
    NSInteger index = 0;
    if (self.selectCheckout && !self.selectPromotion) {
        index = 1;
    }else if (self.selectPromotion && !self.selectCheckout){
        index = 2;
    }else if (self.selectCheckout && self.selectPromotion){
        index = 3;
    }
    
    if (self.staffSelectAccessCellDelegate && [self.staffSelectAccessCellDelegate respondsToSelector:@selector(selectAccessIndex:)]) {
        [self.staffSelectAccessCellDelegate selectAccessIndex:index];
    }
}
#pragma mark -
#pragma mark event

- (IBAction)promotionBtnAction:(id)sender {
    self.promotionStateImg.highlighted = !self.promotionStateImg.isHighlighted;
    self.selectPromotion = !self.selectPromotion;
    [self returnSelectedResult];
}
- (IBAction)checkoutBtnAction:(id)sender {
    self.checkoutStateImg.highlighted = !self.checkoutStateImg.isHighlighted;
    self.selectCheckout = !self.selectCheckout;
    [self returnSelectedResult];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
